﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ExchangeRate.aspx.cs" Inherits="Taxes.ExchangeRate.ExchangeRate" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript">
        function Cancel() {
            window1.hide();
            tfFloor.setValue("");
            tfRate.setValue("");
            ckLift.setValue(false);
        }

        var command = function (cmd, record, rowIndex) {
            if (cmd === 'deleteRate') {
                var result = confirm("删除后无法恢复，确定删除吗?")
                if (result) {
                    Ext.net.DirectMethods.DeleteRate(record.id,
                    {
                        success: function (result) {
                            if (result == 1) {
                                Ext.Msg.alert('提示', "删除成功");
                                grid.reload();
                            }
                            else {
                                Ext.Msg.alert('提示', "删除失败");
                            }
                        }
                    });
                }
            }
            else if (cmd == "updateRate") {
                tfFloor.setValue(record.data.floor_num);
                tfRate.setValue(record.data.floor_converter);
                ckLift.setValue(record.data.floor_elevator);
                tfHidden.setValue("修改");
                tfIDHidden.setValue(record.id);
                window1.show();
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <div>
        <asp:ObjectDataSource ID="odsRate" runat="server" SelectMethod="GetModelList" TypeName="Taxes.BLL.floor_convert">
            <SelectParameters>
                <asp:Parameter DefaultValue="" Name="strWhere" Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <ext:Window runat="server" ID="window1" Width="600" Height="200" Title="添加用户" Padding="5"
            Layout="FormLayout" Hidden="true">
            <Items>
                <ext:Hidden runat="server" ID="tfIDHidden" Text="" />
                <ext:Hidden runat="server" ID="tfHidden" Text="增加">
                </ext:Hidden>
                <ext:TextField ID="tfFloor" runat="server" AllowBlank="false" Regex="^\d{1,2}$" RegexText="只能够输入两位正整数"
                    AnchorHorizontal="100%" FieldLabel="楼层<font color='red'>*</font>">
                </ext:TextField>
                <ext:TextField ID="tfRate" runat="server" AllowBlank="false" AnchorHorizontal="100%"
                    FieldLabel="折算率<font color='red'>*</font>" Regex="^\d+(\.\d+)?$" RegexText="只能够输入数字">
                </ext:TextField>
                <ext:Checkbox ID="ckLift" runat="server" FieldLabel="是否带电梯">
                </ext:Checkbox>
            </Items>
            <Buttons>
                <ext:Button ID="btnSave" runat="server" Icon="Disk" Text="保存">
                    <DirectEvents>
                        <Click OnEvent="btnAdd_Click">
                            <EventMask ShowMask="True" Msg="正在保存,请稍后..." MinDelay="1000" />
                        </Click>
                    </DirectEvents>
                </ext:Button>
                <ext:Button ID="btnCancel" runat="server" Icon="Cancel" Text="取消">
                    <Listeners>
                        <Click Fn="Cancel" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:Window>
        <ext:Store ID="storeExchangeRate" runat="server" DataSourceID="odsRate">
            <Reader>
                <ext:JsonReader IDProperty="ID">
                    <Fields>
                        <ext:RecordField Name="ID" Type="Int" />
                        <ext:RecordField Name="floor_num" Type="Int">
                        </ext:RecordField>
                        <ext:RecordField Name="floor_converter" Type="Float">
                        </ext:RecordField>
                        <ext:RecordField Name="floor_elevator" Type="Int" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
        <ext:GridPanel StoreID="storeExchangeRate" ID="grid" runat="server" Title="折算率理"
            Frame="true" StripeRows="true" Height="400" TrackMouseOver="True" AutoScroll="true">
            <ColumnModel>
                <Columns>
                    <ext:Column ColumnID="colFloor" DataIndex="floor_num" Header="楼层">
                    </ext:Column>
                    <ext:Column ColumnID="colRate" DataIndex="floor_converter" Header="折算率">
                    </ext:Column>
                    <ext:CheckColumn ColumnID="colFloor" DataIndex="floor_elevator" Header="是否带电梯">
                    </ext:CheckColumn>
                    <ext:CommandColumn ColumnID="colDelete" Header="操作">
                        <Commands>
                            <ext:GridCommand Icon="ApplicationEdit" ToolTip-Text="修改" CommandName="updateRate">
                                <ToolTip Text="修改" />
                            </ext:GridCommand>
                            <ext:CommandSeparator />
                            <ext:GridCommand Icon="Delete" ToolTip-Text="删除" CommandName="deleteRate">
                                <ToolTip Text="删除" />
                            </ext:GridCommand>
                        </Commands>
                    </ext:CommandColumn>
                </Columns>
            </ColumnModel>
            <Listeners>
                <Command Fn="command" />
            </Listeners>
            <Buttons>
                <ext:Button ID="btnAdd" runat="server" Text="添加折算率" Icon="Add">
                    <Listeners>
                        <Click Handler="#{window1}.show()" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:GridPanel>
    </div>
    </form>
</body>
</html>
